package com.github.wxpay;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.github.wxpay.sdk.IWXPayDomain;
import com.github.wxpay.sdk.WXPayConfig;
import com.github.wxpay.sdk.WXPayConstants;
import com.util.GetConfig;

public class IWxPayConfig  extends WXPayConfig {
	private byte[] certData;

	private String app_id=GetConfig.getString("appId");//appid

	private String wx_pay_key=GetConfig.getString("payKey");//apikey

	private String wx_pay_mch_id=GetConfig.getString("mchId");//商户号

	public IWxPayConfig() throws Exception { // 构造方法读取证书, 通过getCertStream // 可以使sdk获取到证书
//		String certPath = "/data/config/chidori/apiclient_cert.p12";
//		File file = new File(certPath);
//		InputStream certStream = new FileInputStream(file);
//		this.certData = new byte[(int) file.length()];
//		certStream.read(this.certData);
//		certStream.close();
	}
	@Override
	public String getAppID() {
		return app_id;
	}
	@Override
	public String getMchID() {
		return wx_pay_mch_id;
	}
	@Override
	public String getKey() {
		return wx_pay_key;
	}
	@Override
	public InputStream getCertStream() {
		return new ByteArrayInputStream(this.certData);
	}
	@Override
	public IWXPayDomain getWXPayDomain() { // 这个方法需要这样实现, 否则无法正常初始化WXPay
		IWXPayDomain iwxPayDomain = new IWXPayDomain() {
			@Override
			public void report(String domain, long elapsedTimeMillis,
					Exception ex) {

			}

			@Override
			public DomainInfo getDomain(WXPayConfig config) {
				return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API,
						true);
			}
		};
		return iwxPayDomain;
	}
}
